package com.ktgj.customer.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.customer.domain.CaseType;
import com.ktgj.customer.service.ICaseTypeService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 系统字典_工单类型Controller
 * 
 * @author ruoyi
 * @date 2022-03-03
 */
@RestController
@RequestMapping("/caseType")
public class CaseTypeController extends BaseController
{
    @Autowired
    private ICaseTypeService caseTypeService;

    /**
     * 查询系统字典_工单类型列表
     */
//    @PreAuthorize(hasPermi = "customer:type:list")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody CaseType caseType)
    {
        startPage();
        List<CaseType> list = caseTypeService.selectCaseTypeList(caseType);
        return getDataTable(list);
    }

    /**
     * 导出系统字典_工单类型列表
     */
    @PreAuthorize(hasPermi = "customer:type:export")
    @Log(title = "系统字典_工单类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CaseType caseType) throws IOException
    {
        List<CaseType> list = caseTypeService.selectCaseTypeList(caseType);
        ExcelUtil<CaseType> util = new ExcelUtil<CaseType>(CaseType.class);
        util.exportExcel(response, list, "系统字典_工单类型数据");
    }

    /**
     * 获取系统字典_工单类型详细信息
     */
    @PreAuthorize(hasPermi = "customer:type:query")
    @GetMapping(value = "/{caseTypeId}")
    public AjaxResult getInfo(@PathVariable("caseTypeId") Long caseTypeId)
    {
        return AjaxResult.success(caseTypeService.selectCaseTypeById(caseTypeId));
    }

    /**
     * 新增系统字典_工单类型
     */
    @PreAuthorize(hasPermi = "customer:type:add")
    @Log(title = "系统字典_工单类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CaseType caseType)
    {
        return toAjax(caseTypeService.insertCaseType(caseType));
    }

    /**
     * 修改系统字典_工单类型
     */
    @PreAuthorize(hasPermi = "customer:type:edit")
    @Log(title = "系统字典_工单类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CaseType caseType)
    {
        return toAjax(caseTypeService.updateCaseType(caseType));
    }

    /**
     * 删除系统字典_工单类型
     */
    @PreAuthorize(hasPermi = "customer:type:remove")
    @Log(title = "系统字典_工单类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{caseTypeIds}")
    public AjaxResult remove(@PathVariable Long[] caseTypeIds)
    {
        return toAjax(caseTypeService.deleteCaseTypeByIds(caseTypeIds));
    }
}
